package codetrainning.test1;
/*
自定义方法实现  Arrays工具类中的toString方法,  实现数组中元素的格式化输出
  int [] arr = {88,39,77,56,89,99,59,97};
 */
public class Demo1 {
    public static void main(String[] args) {
        int [] arr = {88,39,77,56,89,99,59,97};
        String arrStr = toString(arr);
        System.out.println(arrStr);
    }

    public static String toString(int [] arr){
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < arr.length; i++) {
            if(i == arr.length-1){
                sb.append(arr[i]+"]");
            }else {
                sb.append(arr[i]+",");
            }
        }
        return sb.toString();
    }
}
